#include <QFileSystemModel>
#include <QFile>
#include <QDir>

#include "cmd_homepage_new.h"
#include "ui_cmd_homepage_new.h"

cmd_homepage_new::cmd_homepage_new(QWidget *parent) : QDialog(parent),ui(new Ui::cmd_homepage_new){
    ui->setupUi(this);
    connect(ui->FOLDER, SIGNAL(clicked(bool)), this, SLOT(onbtnclicked_FOLDER()));
    connect(ui->SCRIPT, SIGNAL(clicked(bool)), this, SLOT(onbtnclicked_SCRIPT()));
    connect(ui->CANCEL, SIGNAL(clicked(bool)), this, SLOT(onbtnclicked_CANCEL()));
}

cmd_homepage_new::~cmd_homepage_new(){
    delete ui;
}

void cmd_homepage_new::onbtnclicked_FOLDER(){
    QString Name;
    QString foldername;
    QDir *mfolder = nullptr;

    Name.clear();
    foldername.clear();

    Name = ui->lineEdit->text();
    foldername  = CurDir + "/"+ Name;

    mfolder = new QDir;
    mfolder->mkpath(foldername);
    delete mfolder;
    this->close();
}

void cmd_homepage_new::onbtnclicked_SCRIPT(){
    QString Name;
    QString filename;
    QFile *mSaveFile = nullptr;
    Name.clear();
    filename.clear();

    Name = ui->lineEdit->text();
    filename  = CurDir + "/"+ Name + ".xml";

    mSaveFile = new QFile(filename);
    mSaveFile->open(QIODevice::WriteOnly | QIODevice::Text);
    mSaveFile->close();
    delete mSaveFile;
    this->close();
}

void cmd_homepage_new::onbtnclicked_CANCEL(){
    this->close();
}


